<!DOCTYPE html>
<meta http-equiv = "content-type" content = "text/html; charset = UTF-8">
<?php
	session_start();
	include("conn.php");
	if(isset($_GET['id']))
	{
		$id=$_GET['id'];
		$sql = "SELECT * FROM content WHERE id=$id";
		$query= mysql_query($sql);
		while($row=mysql_fetch_array($query))
		{
			$title=$row['title'];
			$content=$row['content'];
		}
	}
?>
<html>
	<head>
		<title>我的主页-修改留言</title>
		<link rel = "stylesheet" href = "base.css">
		<style>
			div#content {
				height: 319px;
				width: 1190px;
				margin-top:0;
				float: left;
				
			}
			div#page {
				height: 319px;
				width: 300px;
				float: left;
			}
			div#msgboard {
				height: 319px;
				margin-top: 50px;
				float: left;
			}
			div#header {
				width: 1040px;
				text-align: center;
				float: left;
			}
			div#logo {
				width: 150px;
				float: left;
			}
			h1 {
				font-size: 18px;
			}
		</style>
	</head>
	<body class = "content">
		<div id="container">
			<div id = "logo">
				<img src = "image/logo.gif"  width = "150px" height = "50px"/>
			</div>
			<div id = "header">
				<h1><a href = "index2.php">首页</a> | <a href = "msgboard.php">留言板</a> | <a href = "message.php">查看留言</a> | <a href = "userinfo.php">个人信息</a> | 
					<a href = "exit.php">退出</a></h1>
				<div id = "hello">
					<?php
					echo "$_SESSION[user] 你好！";
					?></div>
			</div>
		<div id = "content">
			<hr>
			<div id = "page"></div>
			<div id = "msgboard">
				<form action = "", method = "post">
				<div>标题：<input type = "text" name = "title" size = 24></div>
				<div>内容：<br/>
				<textarea type = "text" name = "content" rows="10" cols="80"></textarea>
				<div><input type = "submit" name = "modify" value = "修改">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset"></div>	
				</form>
			</div>
			</div>
		</div>
		<div id="footer"><hr>Copyright © 2014 xiaolongge</div>
		</div>
		<?php
			if (isset($_POST["modify"]))
			{
				if($_POST["title"]=="" ) {
					echo "<script>alert('标题不能为空！');</script>";
				}
				if($_POST["content"]=="") {
					echo "<script>alert('内容不能为空！');</script>";
				}
				$userinfo = $_SESSION['user'];
				$sql = "UPDATE content SET title = '$_POST[title]', content = '$_POST[content]' WHERE id = '$id'";
				mysql_query($sql);

				echo "<script>alert('留言修改成功！点确定查看留言');location.href='message.php';</script>";
			}
		?>
	</body>
</html>